package configuration

import (
	"fmt"
	"v8s/logger"

	server "v8s/http-server"

	"github.com/caarlos0/env/v6"
)

type (
	Properties struct {
		Log                  logger.Properties           `envPrefix:"LOG_"`
		Mongo                MongoProperties             `envPrefix:"MONGO_"`
		HttpServer           server.HttpServerProperties `envPrefix:"HTTP_"`
		ManagementHttpServer server.HttpServerProperties `envPrefix:"MANAGEMENT_"`
		V8SController        V8SControllerProperties     `envPrefix:"V8S_CONTROLLER_"`
		Features             FeaturesProperties          `envPrefix:"FEATURES_"`
	}

	MongoProperties struct {
		ConnectionURI string `env:"CONNECTION_URI"`
		Database      string `env:"DATABASE,notEmpty"`
	}

	V8SControllerProperties struct {
		Host string `env:"HOST"`
	}

	FeaturesProperties struct {
		DeleteAllTasksEnabled bool `env:"DELETE_ALL_TASKS_ENABLED" envDefault:"false"`
	}
)

func ReadProperties() *Properties {
	config := &Properties{}

	if err := env.Parse(config); err != nil {
		panic(fmt.Errorf("read config error: %w", err))
	}

	fmt.Printf("config: %+v", config)
	return config
}
